package com.cooper.controllers.dev;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.cooper.core.JsonResult;
import com.cooper.resource.IResourceManager;
import com.cooper.resource.ResourceLoaderItem;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;

public class ResourceController {

	@Autowired
	private IResourceManager resourceManager;
	
	@SuppressWarnings("unchecked")
	@Get
	public String listAll(Invocation inv) {
		List<ResourceLoaderItem> ret = (List<ResourceLoaderItem>) resourceManager.getResList(IResourceManager.RESOURCE_LOADER_ITEMS);
		inv.addModel("dataList", ret);
		return "ResourceMain";
	}
	
	@Get("refresh") 
	@Post("refresh")
	public Object refreshResource(JsonResult json,@Param("resName") String resName) {
		try{
			boolean result = resourceManager.refresh(resName);
			json.setSuccess(result);
		} catch(Exception e){
			json.setMessage(e.getMessage());
		}
		return json;
	}
	
}
